# -*- coding: utf-8 -*-

import pygame
from pygame.locals import KEYDOWN
import time

# 初始化pygame
pygame.init()

# 创建窗体
screen = pygame.display.set_mode(size=(800, 600))
# 设置窗口标题
pygame.display.set_caption("贪吃蛇V1.0")
# 设置窗口图标
icon_image = pygame.image.load("贪吃蛇/res/icon.png")
pygame.display.set_icon(icon_image)
# 设置背景色
COLOR = (200, 200, 0)
# 准备图片
plane_image = pygame.image.load("贪吃蛇/res/head-red.png")
# 旋转
plane_image = pygame.transform.rotate(plane_image, 90)
clock = pygame.time.Clock()

while True:
    # 处理事件，获取用户输入事件
    event_list = pygame.event.get()
    for event in event_list:
        if event.type == pygame.QUIT:
            # 退出游戏
            pygame.dispaly.quit()
            exit(0)
        elif event.type == pygame.KEYDOWN:
            print("按键被按下:",event.key)
    # 绘制界面
    screen.fill(COLOR)
    # 绘制图片
    screen.blit(plane_image,(10,10))
    # 刷新界面
    pygame.display.flip()
    # 主动休眠减少刷新速度
    # time.sleep(1/60)
    clock.tick(10) # 10帧每秒，确保内部跑足0.1s
    print("fps:",clock.get_fps())


